package com.jhgsys.internal.workflow.controller;

import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.workflow.entity.WorkflowNode;
import com.jhgsys.internal.workflow.service.IWorkflowNodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 流程节点表 Controller
 *
 * @author fenghaijun
 * @date 2024-07-19 08:55:30
 */
@Slf4j
@Validated
@Controller
public class WorkflowNodeController extends BaseController {

    @Autowired
    private IWorkflowNodeService workflowNodeService;


    /**
     * 流程节点配置自定义回调实现类
     * @param classType 1: 自定义审核权限实现 2:自定义节点按钮执行事件实现 3:自定义抄送实现
     * @return
     * @throws FebsException
     */
    @GetMapping("workflowNode/queryWorkflowCustomBean")
    @ResponseBody
    public FebsResponse queryWorkflowCustomBean(String classType) {
        String[] workflowCustomBeanList = this.workflowNodeService.queryWorkflowCustomBean(classType);
        return new FebsResponse().success().data(workflowCustomBeanList);
    }

    /**
     * 根据workflowNodeId查询对应的流程节点
     */
    @PostMapping("workflowNode/selectInfoByWorkflowNodeId")
    @ResponseBody
    public FebsResponse selectInfoByWorkflowNodeId(@RequestBody WorkflowNode workflowNode){
        return new FebsResponse().success().data(workflowNodeService.findWorkflowNodeById(workflowNode.getWorkflowNodeId()));
    }

    /**
     * 流程节点配查询对应表
     * @return
     * @throws FebsException
     */
    @GetMapping("workflowNode/queryWorkflowTable")
    @ResponseBody
    public FebsResponse queryWorkflowTable() {
        List<Map<String,String>> table = workflowNodeService.selectTable();
        return new FebsResponse().success().data(table);
    }

    /**
     * 流程节点配查询对应表字段
     * @return
     * @throws FebsException
     */
    @GetMapping("workflowNode/queryWorkflowTableColums")
    @ResponseBody
    public FebsResponse queryWorkflowTableColums(String name) {
        List<Map<String,String>> stringList = workflowNodeService.queryWorkflowTableColums(name);
        return new FebsResponse().success().data(stringList);
    }
}
